﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class profiles : System.Web.UI.Page
{
    private string path = "";
    private SQLQuery sqlQuery = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["candidate"] == null)
        {
            Response.Redirect("index.aspx");
        }
        loadUserControls();
        sqlQuery = new SQLQuery();
        path = Server.MapPath(".") + "//image//avatar//candidate//";
                
        if (!IsPostBack)
        {
            txt_email.Text = Session["candidate"].ToString();
            txt_name.Text = LocalVariables.ARRAY_INFOR_CANDIDATE[0];
            bdp_birthday.SelectedValue = LocalVariables.ARRAY_INFOR_CANDIDATE[1];
            txt_address.Text = LocalVariables.ARRAY_INFOR_CANDIDATE[2];
            txt_city.Text = LocalVariables.ARRAY_INFOR_CANDIDATE[3];
            txt_country.Text = LocalVariables.ARRAY_INFOR_CANDIDATE[4];
            ftb_description.Text = LocalVariables.ARRAY_INFOR_CANDIDATE[5];
            txt_phone.Text = LocalVariables.ARRAY_INFOR_CANDIDATE[6];
        }
    }

    private void loadUserControls()
    {
        string path = "panel/menulist.ascx";
        panel_menulist.Controls.Clear();
        UserControl userControl = (UserControl)LoadControl(path);
        panel_menulist.Controls.Add(userControl);
    }

    protected void btn_save_Click(object sender, EventArgs e)
    {
        string email = txt_email.Text.ToString().Trim();
        string name = txt_name.Text.ToString().Trim();
        string address = txt_address.Text.ToString().Trim();
        string city = txt_city.Text.ToString().Trim();
        string country = txt_country.Text.ToString().Trim();
        string phone = txt_phone.Text.ToString().Trim();
        string decription = ftb_description.Text.ToString().Trim();
        string birthday = bdp_birthday.Text.ToString().Trim();
        string avatar = "";
        if (file_upload.HasFile)
        {
            avatar = LocalVariables.getFileName("", file_upload.FileName);
        }
        if (sqlQuery.updateTableCandidate(email, "", name, birthday, address, city, country, decription, phone, avatar))
        {
            LocalVariables.ARRAY_INFOR_CANDIDATE[0] = name;
            LocalVariables.ARRAY_INFOR_CANDIDATE[1] = birthday;
            LocalVariables.ARRAY_INFOR_CANDIDATE[2] = address;
            LocalVariables.ARRAY_INFOR_CANDIDATE[3] = city;
            LocalVariables.ARRAY_INFOR_CANDIDATE[4] = country;
            LocalVariables.ARRAY_INFOR_CANDIDATE[5] = decription;
            LocalVariables.ARRAY_INFOR_CANDIDATE[6] = phone;
            if (file_upload.HasFile)
            {
                LocalVariables.ARRAY_INFOR_CANDIDATE[7] = avatar;
                file_upload.SaveAs(path + avatar);
            }
            lbl_msg.Text = LocalVariables.EDIT_PROFILE_USER;
            layout_back.Visible = true;
            layout_infor.Visible = false;
        }
    }
}